package com.iaz.tech.tools.common.flow.impl;

import com.iaz.tech.tools.common.flow.IFlowAble;
import lombok.Data;
import lombok.EqualsAndHashCode;

import java.util.ArrayList;
import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * 进行
 */
@EqualsAndHashCode(callSuper = true)
@Data
public class FlowsGroup extends FlowNode{
    
    /**
      * 日志
      */
	private final static Logger logger = (Logger) LoggerFactory.getLogger(FlowsGroup.class);

    private List<IFlowAble> flows = new ArrayList<>();

    /**
     * 判断是否为空
     * @return
     */
    public boolean isEmpty() {
        return this.flows == null ? true:this.flows.isEmpty();
    }

    /**
     * 执行流程
     */
    @Override
    public Object executeFlow(Object property) {
        Object result = null;
        try {
            if (this.getFlows().isEmpty()) {
                logger.warn("catch 语句没有流程");
                return result;
            }
			for (IFlowAble flow : this.getFlows()) {
				flow.executeFlow(property);
			}
		} catch(Exception e) {
			logger.error("catch 异常", e);
		}
        return result;
    }
    /**
     * 执行前处理
     */  
    @Override
    public Object beforeExecute(Object property) {
        Object result = null;
        return result;
    }
    /**
     * 执行后处理
     */
    @Override
    public Object afterExecute(Object property) {
        Object result = null;
        return result;
    }
}
